package org.genntii.smcommon.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ErrorMessageConfiguration {

    public static final String errorRoutingKey = "error";

    public static final String errorDirectExchange = "error.direct";

    public static final String errorMessageQueue = "error.queue";

    @Bean
    public DirectExchange errorDirectExchange() {
        return new DirectExchange(errorDirectExchange);
    }

    @Bean
    public Queue errorMessageQueue() {
        return new Queue(errorMessageQueue);
    }

    @Bean
    public Binding errorQueueBinding() {
        return BindingBuilder.bind(errorMessageQueue()).to(errorDirectExchange()).with(errorRoutingKey);
    }

//    @Bean
//    public MessageRecoverer messageRecoverer(RabbitTemplate rabbitTemplate) {
//        return new RepublishMessageRecoverer(rabbitTemplate, errorDirectExchange, errorRoutingKey);
//    }
}
